#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(x,y,z) for(int x=(y);x<=(z);x++)
#define per(x,y,z) for(int x=(y);x>=(z);x--)
#define mid (l+r>>1LL)
#define repn(x) rep(x,1,n)
#define repm(x) rep(x,1,m)
#define pb push_back
#define Pi pair<int,int>
#define e(x) for(int i=h[x],y=to[i];i;i=nxt[i],y=to[i])
#define E(x) for(auto y:p[x])
inline int read(){int s=0,w=1;char c=getchar();while(c<48||c>57){if(c=='-')w=-1;c=getchar();}while(c>=48&&c<=57)s=(s<<1)+(s<<3)+c-48,c=getchar();return s*w;}
const int N=2e6+5,M=1e6+5,inf=(1LL<<31)-1,mod=1e9+7;
const ll llf=1e18;
inline void add(int &a,int b){((a+=b)>=mod) and (a-=mod);}
inline int Add(int a,int b){return add(a,b),a;}
inline int mul(int a,int b){return 1LL*a*b%mod;}
inline void Mul(int &a,int b){a=mul(a,b);}
inline void red(int &a,int b){add(a,mod-b);}
inline int Red(int a,int b){return red(a,b),a;}
inline int qp(int a,int b){if(!b)return 1;int c=qp(a,b>>1);Mul(c,c);if(b&1)Mul(c,a);return c;}
int n,d[N],Slen,MAXx;
vector<int>p[N];
bool Ans[N];
int c[N];
inline void Out(){
	int Nw=0;
	bool fl=0;
	per(i,N-1,0){
		if(Ans[i])fl=1;
		if(fl)putchar('0'+Ans[i]);
	}
	exit(0);
}
inline void subtaskA(){
	repn(i)c[p[i].back()]++;
	int Tot=0,ct=0;
	rep(i,0,N-1){
		Tot+=c[i],ct+=c[i];
		if(ct)Ans[i]=1,ct--;
		if(Tot&&!ct)Out();
	}
}
bool v[N][2];
inline void subtask1(){
	for(auto x:p[1])v[x][0]=1;
	for(auto x:p[2])v[x][1]=1;
	rep(l,0,N-1){
		if(!v[l][0]&&!v[l][1])continue;
		if(!v[l][0]||!v[l][1]){
			Ans[l]=1;
			continue;
		}
		int ra=l,rb=l;
		while(v[ra+1][0])ra++;
		while(v[rb+1][1])rb++;

		if(ra>=rb){
			rep(i,l,ra)v[i][0]=0;
			v[ra+1][0]=1;
			rep(i,l,rb)Ans[i]=1;
			l=rb;
		}else {
			rep(i,l,rb)v[i][1]=0;
			v[rb+1][1]=1;
			rep(i,l,ra)Ans[i]=1;
			l=ra;
		}
	}
	Out();
}
bool u[6],used[32];
int ansLen=inf,ansK,Ct[32];
inline void dfs(int pos){
	if(pos==32){
		int C=0,Sm=0;
		rep(i,1,31){
			C+=Ct[i];
			if(used[i]){
				if(!C)return;
				C--,Sm+=i;
			}
		}
		if(C>ansLen)return;
		if(C<ansLen)ansLen=C,ansK=Sm;
		else if(C==ansLen)ansK=min(ansK,Sm);
		return;
	}
	used[pos]=0,dfs(pos+1);
	bool fl=1;
	rep(i,0,4)if((pos>>i)&1)fl&=!u[i];
	if(fl){
		used[pos]=1;
		rep(i,0,4)if((pos>>i)&1)u[i]=1;
		dfs(pos+1);
		rep(i,0,4)if((pos>>i)&1)u[i]=0;
	}
}
inline void subtask2(){
	repn(i){
		int s=0;
		for(auto x:p[i])s|=1<<x;
		Ct[s]++;
	}
	dfs(1);
	rep(i,0,4)Ans[i]=(ansK>>i)&1;
	rep(i,1,ansLen)Ans[4+i]=1;
	Out();
}
inline void Main(){
	n=read();
	repn(i){
		d[i]=read(),Slen+=d[i];
		rep(j,1,d[i])p[i].pb(read()-1),MAXx=max(MAXx,p[i].back());
	}
	if(Slen==n)return subtaskA();
	if(n<=2)return subtask1();
	if(MAXx<=4)return subtask2();
}
signed main(){
	freopen("mcmf.in","r",stdin);
	freopen("mcmf.out","w",stdout);
	int T=1;
	while(T--)Main();
	return 0;
}